Skip to content

fix(desktop): derive avatar initials by character, not code unit - #5992

Open
Chessing234 wants to merge 3 commits into
block:mainfrom
Chessing234:fix/initials-astral-names
Open

fix(desktop): derive avatar initials by character, not code unit#5992
Chessing234 wants to merge 3 commits into
block:mainfrom
Chessing234:fix/initials-astral-names

Conversation

@Chessing234

Copy link
Copy Markdown
Contributor

Found by probing getInitials with non-Latin names; no issue filed. It feeds every avatar fallback in the app — UserAvatar, ProfileAvatar, IdentityInitialsAvatar, CommunityRail.

Two separate bugs, one commit each.

Half a surrogate pair. The function took part[0], a UTF-16 code unit. A name whose first letter lives outside the Basic Multilingual Plane is a surrogate pair, so that returned half of one — not a character:

"𠀀明"          →  "\ud840"      (a lone high surrogate, renders as �)
"𝐀da Lovelace" →  "\ud835L"

CJK Extension B appears in ordinary Chinese and Japanese given names, so every avatar for such a person rendered . Now iterating code points, and taking two of them before joining rather than slicing two code units off the result, so the second initial can't be halved either.

A word cut in half at a combining mark. Marks are neither \p{L} nor \p{N}, so they were replaced with a separator — cutting words apart from the inside:

name before after
अनिल कुमार अल अक
नमस्ते नत
မောင်မောင် မင

"अनिल कुमार" split at the vowel sign into "अन" and "ल", so both initials came from the middle of the first name and the surname was never reached; a one-word name produced two initials where there is one word to initial. Devanagari, Burmese, Thai and Khmer names take marks in ordinary spelling. \p{M} is now kept alongside letters and numbers — punctuation is still stripped, and the existing "B (relay)" → "BR" case is pinned by a test in both commits.

Verified locally at this head:

  • pnpm test4961 passed, 0 failed (4954 before, plus the 7 new)
  • pnpm check — clean; its 2 warnings and 2 infos are pre-existing and identical on main
  • pnpm build — succeeded

Note: I'm an outside contributor, so the workflow runs here sit at action_required until a maintainer approves them; only the DCO check reports on its own.

`getInitials` took `part[0]`, a UTF-16 code unit. A name whose first letter
lives outside the Basic Multilingual Plane is a surrogate pair, so that
returned half of one — not a character. CJK Extension B appears in ordinary
Chinese and Japanese given names, and every avatar for such a person rendered
`�`.

Iterate code points, and take two of them before joining rather than slicing
two code units off the result, so the second initial cannot be halved either.

Signed-off-by: Taksh <takshkothari09@gmail.com>
Combining marks are neither `\p{L}` nor `\p{N}`, so `getInitials` replaced
them with a separator and cut words apart from the inside. "अनिल कुमार" split
at the vowel sign into "अन" and "ल", producing "अल" — two letters from the
middle of the first name, with the surname never reached. A one-word name
like "नमस्ते" produced two initials where there is one word to initial.
Devanagari, Burmese, Thai and Khmer names take marks in ordinary spelling.

Keep `\p{M}` alongside letters and numbers. Punctuation is still stripped, so
"B (relay)" still gives "BR".

Signed-off-by: Taksh <takshkothari09@gmail.com>

@themiguelamador themiguelamador left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The astral-code-point and word-splitting fixes are good, but the new implementation still truncates initials at a code point rather than a grapheme cluster. For example, decomposed E\u0301lodie Durand returns ED and drops the accent even though the new contract says combining marks remain part of the word. The existing Indic expectations similarly discard the surname vowel sign (कु) and the first Burmese grapheme (မေ). Join controls are also stripped, so an ordinary joined cluster such as क्‍ष is split into two initials. I prepared local signed commit d694a2c6e, using the project’s established Intl.Segmenter approach, preserving Join_Control, and adding/correcting regressions. Verification: 13 focused tests; all 4,963 desktop unit tests; TypeScript; Biome; file-size gate; pre-commit. I attempted to push it to the contributor branch because maintainer edits are enabled, but GitHub returned 403.

Review caught that the previous commits stopped half way. Moving from code
units to code points fixed the lone surrogate, but an initial is neither:

- decomposed `Élodie Durand` gave `ED`, dropping the accent, though the
  contract these commits added says a mark stays with its letter
- `अनिल कुमार` gave `अक`, dropping the surname's vowel sign — `कु` is one
  cluster
- `မောင် မောင်` gave `မမ` rather than `မေမေ`
- `क्‍ष` was split into two initials, because the zero-width joiner holding it
  together is neither a letter nor a mark and so acted as a word separator

Segment by grapheme via `Intl.Segmenter`, guarded and falling back to a code
point exactly as `MessageLinkPill` does, and keep `\p{Join_Control}` in the
word-separation set alongside `\p{M}`.

Two of the tests added earlier asserted the code-point results (`अक`, `မ`) as
if they were correct. They were not; they are corrected here rather than kept
as a description of the bug.

Signed-off-by: Taksh <takshkothari09@gmail.com>
@Chessing234

Copy link
Copy Markdown
Contributor Author

you're right on all four, thanks — i reproduced each one before changing anything:

"Élodie Durand"  => "ED"    (accent dropped)
"अनिल कुमार"      => "अक"    (should be अकु)
"မောင် မောင်"    => "မမ"    (should be မေမေ)
"क्‍ष Name"       => "कष"    (ZWJ split one word into two initials)

the code-point step fixed the lone surrogate and then stopped. worse, two of the tests i added asserted the code-point results (अक, ) as if they were correct. they weren't — corrected here rather than left as a description of the bug.

pushed 3bb067a1:

  • Intl.Segmenter with the typeof … === "function" guard and Array.from fallback, copying MessageLinkPill's shape rather than inventing one. i'd avoided segmenter earlier over fix(desktop): ship a bundle that parses on WebKit without lookbehind (Intel/macOS 12) #5547's webkit history — over-cautious, given it's already used in MessageLinkPill and terminalRenderer, and the guard covers exactly what i was worried about.
  • \p{Join_Control} added to the word-separation keep-set alongside \p{M}.
  • the four cases now give ÉD / अकु / မေမေ / क्‍षN, with the existing AS, BR, 𠀀 and "" cases unchanged.

one note on the decomposed case: the initial keeps the input's own normalization, so Élodie returns a decomposed ÉD rather than a recomposed one. they render identically; the test pins both forms so the intent is explicit.

verification: 14 focused tests, full desktop suite 4964 passed / 0 failed, pnpm check clean (same 2 warnings + 2 infos as main), pnpm build ok.

@themiguelamador themiguelamador left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed current head 3bb067a19. This resolves the prior grapheme-cluster finding: initials now use Intl.Segmenter, preserve join controls, retain decomposed accents and Indic vowel signs, and keep a code-point fallback for older engines. The new expectations and regressions cover the reported cases.

Verified with the full desktop unit suite, TypeScript, focused Biome, file-size ratchet, and git diff --check. No remaining findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants